// 封装token
// 1.gettoken获取token
// 2.settoken  设置token
// 3.cleartoken 清除token

import { Token } from '@/types/data';

// 4.isAuth  是否登录
const GEEK_TOKEN = 'zhoumeili';

export const getToken = () =>
  JSON.parse(
    localStorage.getItem(GEEK_TOKEN) ?? '{"token":"","refresh_token":""}'
  ) as Token;

export const setToken = (token: Token) =>
  localStorage.setItem(GEEK_TOKEN, JSON.stringify(token));

export const cleartoken = () => localStorage.removeItem(GEEK_TOKEN);

export const isAuth = () => !!getToken().token;
